<template>
	<view class="pics">
		<scroll-view scroll-y="true" class="left">
			<view :class="active===index?'active':'' " @click="leftClickHandle(index,item.id)"
			v-for="(item,index) in cates" :key="item.cat_id">{{item.cat_name}}</view>
		</scroll-view>
		<scroll-view scroll-y="true" class="right">
			<view class="item" v-for="(item,index) in secondData" :key="item.id" >
				<image @click="preImage(item.img)" :src="item.img" mode=""></image>
				<text>{{item.title}}</text>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				cates:[],
				active:0,
				secondData:[]
			}
		},
		onLoad() {
			this.getPicsCate()
		},
		methods: {
			getPicsCate(){
				this.$myRequest({
					url:'getImgCategory.json'
				}).then(res=>{
					console.log(res.data.message)
					this.cates = res.data.message
					this.leftClickHandle(0,this.cates[0].id)
				})
			},
			leftClickHandle(index,id){
				this.active = index
				// 获取右部的数据
				this.$myRequest({
					// url:'getDateByCategory.json'+id
					url:'getDateByCategory.json'
				}).then(res=>{
					console.log( res.data.message)
					this.secondData = res.data.message
				})
			},
			preImage(current_img){
				const urls = this.secondData.map(item=>{
					return item.img
				})
				uni.previewImage({
					urls:urls,
					current:current_img
				})
			}
			
		}
	}
</script>

<style lang="scss">
	pages{
		height: 100%;
	}
	.pics{
		height: 100%;
		display: flex;
		.left{
			width: 200rpx;
			height: 100%;
			border-right: 1px solid #eee;
			view{
				height: 60px;
				line-height: 60px;
				color: #333;
				text-align: center;
				font-size: 30rpx;
				border-top: 1px solid #eee;
			}
			.active{
				background: $shop-color;
				color: #fff;
			}
		}
		.right{
			height: 100%;
			width: 520rpx;
			margin: 10rpx auto;
			.item{
				image{
					width: 520rpx;
					height: 520rpx;
					border-radius: 5px;
				}
				text{
					font-size: 30rpx;
					line-height: 60rpx;
				}
			}
		}

	}
</style>
